﻿

using BG.Helpers.Model;
using System.Net.Mail;
using System;
using System.Net;
namespace BG.Helpers.DAL
{
    public class EmailMessageManager
    {
        public static bool SendEmailMessage(EmailMessage model)
        {
            bool success = false;
            try
            {
                var smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(model.from, model.fromPassword)
                };
                using (var message = new MailMessage(model.from, model.to)
                {
                    IsBodyHtml=true,
                    Subject = model.subject,
                    Body = model.emailbody
                })
                {
                    smtp.Send(message);
                }

                success = true;
            }
            catch (Exception ex)
            {
                success = false;
            }
            return success;
        }

        public static bool SendEmailMessage2(EmailMessage model)
        {
            bool success = false;
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress(model.from);
                message.To.Add(new MailAddress(model.to));

                message.Subject = model.subject;
                message.Body = model.emailbody;

                SmtpClient client = new SmtpClient();
                client.Send(message);


                success = true;
            }
            catch (Exception ex)
            {
                success = false;
            }
            return success;
        }
    }
}
